package com.jhhc.Config;

import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.springframework.boot.context.properties.ConfigurationProperties;

import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;
import java.util.Properties;

/**
 * @Author ZhangLe
 * @Date 2020/11/20 19:41
 */
@Configuration
public class DataSourceConfig {

    /**
     * 数据源1 引用配置文件 rhdb
     * @return
     */
    @Primary
    @Bean(name = "rhdbDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.rhdb")
    public DataSource dataSourceSentence() {

        return DataSourceBuilder.create().build();
    }
    /**
     * 数据源2  引用配置文件 flood
     * @return
     */

    @Bean(name = "floodDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.flood")
    public DataSource dataSourcePreprocess() {
        return DataSourceBuilder.create().build();
    }


    /**
     * 数据源3  引用配置文件 weatherDataSource
     * @return
     */

    @Bean(name = "weatherDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.weather")
    public DataSource dataSourcePreprocess1() {
        return DataSourceBuilder.create().build();
    }


    /**
     * 数据源3  引用配置文件 tide
     * @return
     */

    @Bean(name = "astronomicaltideDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.astronomicaltide")
    public DataSource dataSourcePreprocess2() {
        return DataSourceBuilder.create().build();
    }


    @Bean(name = "stormsurgeDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.stormsurge")
    public DataSource dataSourcePreprocess3() {
        return DataSourceBuilder.create().build();
    }


    @Bean(name = "tideDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.tide")
    public DataSource dataSourcePreprocess4() {
        return DataSourceBuilder.create().build();
    }


    @Bean(name = "wqDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.wq")
    public DataSource dataSourcePreprocess7() {
        return DataSourceBuilder.create().build();
    }
    @Bean(name = "bdmsDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.bdms")
    public DataSource dataSourcePreprocess8(){
        return DataSourceBuilder.create().build();
    }



    @Bean
    public DatabaseIdProvider databaseIdProvider() {
        VendorDatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
        Properties properties = new Properties();
        properties.put("SQL Server","sqlserver");
        properties.put("MySQL","mysql");
        properties.put("PostgreSQL","pgsql");
        properties.put("DM DBMS","dm");
        databaseIdProvider.setProperties(properties);
        return databaseIdProvider;
    }

}
